/*
 * MeasWorld.cpp
 *
 *  Created on: Oct 19, 2012
 *      Author: johnny
 */

#include "MeasWorld.h"

namespace core {

MeasWorld& MeasWorld::getInstance() {
    static MeasWorld INSTANCE;
    return INSTANCE;
}

MeasWorld::MeasWorld():
		cfgManager(ConfigurationManager::getInstance()),
        engine(Engine::getInstance()), engineThreadRun(NULL), genericMIThreadRun(NULL) {


    Logger::getInstance().add(Information, "Started MTS World", L"MTS");
}

MeasWorld::~MeasWorld() {
    if(engineThreadRun != NULL) {
        delete engineThreadRun;
    }
}

bool MeasWorld::setup() { //todo: set user directory from ini
    const boost::filesystem::path& libDir = util::getDir(util::MoDir);
    Logger::getInstance().add(Debug, "Starting MTS setup", L"MTS");

    //engine.loadSysMOs();
	engine.scanMOs(libDir);
    engineThreadRun = new boost::thread(engineThread);

	return true;
}

bool MeasWorld::loadRec(std::string rec) {
	(void)rec; //todo: load rec
	return true;
}

void MeasWorld::close() {
    engine.stopRunning();
    engineThreadRun->join();
}

} /* namespace core */
